<template>
	<view class="mainpadding beijingse">
		<!-- 筛选弹出层 -->
		<u-popup :show="show" @close="close(1)" mode="bottom" :round="10">
			<view class="mainpadding">
				<view class="titletext textcenter">筛选</view>
				<view class="margin_top strongtext">时间</view>
				<view class="flexleft flex_wrap">
					<view class="flexcenter sanshi margin_top2" v-for="item in timeList" :key="item.id" @click="changelx(item.id)">
						<view :class="item.id==selecttime?'haungsebtn':'huisebtn'">
							{{item.name}}
						</view>
					</view>
				</view>
				<!-- 时间 -->
				<view class="margin_top strongtext">自定义时间</view>
				<view class="flexcenter margin_top2" @click="zdysj">
					<view class="shijianbtn margin_right3" @click="zshijian">{{startime}}</view>
					<view class="xian margin_right3"></view>
					<view class="shijianbtn" @click="yshijian">{{endtime}}</view>
				</view>
				<u-datetime-picker :show="zshow" @confirm="zconfirm" v-model="value1" mode="date"
					@cancel="zshow= false"></u-datetime-picker>
				<u-datetime-picker :show="yshow" @confirm="yconfirm" v-model="value2" mode="date" @cancel="yshow= false"
					:minDate="mindate"></u-datetime-picker>
				<view class="bigbtn margin_top" @click="close(2)">确认</view>
			</view>
		</u-popup>
		<view class="toububjt margin_top">
			<view class="bigbtext textcenter">{{token_price?token_price:'0.00'}}</view>
			<view class="xbtext margin_top1 textcenter">我的本金</view>
			<view class="flexcenter margin_top6">
				<view class="baibtn" @click="tztxclick">提现</view>
			</view>
		</view>
		<view class="flexbetween margin_top">
			<view class="dingwei">
				<view class="titletext">本金明细</view>
				<view class="zitbjs"></view>
			</view>
			<view class="flexright" @click="show = true">
				<view class="zhtext margin_right1">筛选</view>
				<view class="shaxicon"></view>
			</view>
		</view>
		<!--筛选内容 -->
		<view class="ffffff mainpadding radius mainpadding margin_top" v-if="list.data.length">
			<view class="xiahuax" v-for="item in list.data" :key="item.id">
				<view class="flexbetween">
					<view class="ershib1">{{item.memo}}</view>
					<view class="qianshu">{{item.token_price}}</view>
				</view>
				<view class="margin_top1 qhtext">{{item.createtime_text}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				// 时间
				startime: "开始时间",
				endtime: "结束时间",
				// 数据列表
				show: false,
				mindate: "",
				//开始时间
				zshow: false,
				value1: Number(new Date()),
				//结束
				yshow: false,
				value2: Number(new Date()),
				// 筛选
				timeList: [{
						id: 1,
						name: "今日"
					},
					{
						id: 2,
						name: "昨日"
					},
					{
						id: 3,
						name: "本月"
					},
					{
						id: 4,
						name: "上月"
					}
				],
				selecttime: 0, //筛选时间类型
				personInfo:{
					styc_token_price:""
				},
				page: 1,
				limit: 12,
				list: {
					data: [{
						token_price:"",
						memo:"",
						bj_token_price:"",
						createtime_text:"",
					}]
				},
				styc_account_id:'',
				token_price:''
			}
		},
		onLoad(options){
			this.styc_account_id=options.styc_account_id
		},
		onShow() {
			this.getinfo()
			this.init()
		},
		methods: {
			// 热门推荐列表
			init(isPage, page) {
				let _this = this;
				httpRequest.request("/api/stycorder/stycRecord", 'POST', {
					start_time: this.startime=="开始时间"?'':this.startime,
					end_time: this.endtime=="结束时间"?'':this.endtime,
					sx_type: this.selecttime, //筛选类型
					page: page || 1,
					limit: this.limit,
					type:2,
					styc_account_id:this.styc_account_id
				}, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
				httpRequest.request('/api/stycorder/myStycDetail', 'POST', {
					id:this.styc_account_id
				}, false, false, true).then(res => {
					if (res.code == 1) {
						this.token_price=res.data.token_price
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			getinfo() {
				httpRequest.request('/api/user/index', 'POST', {}, false, false, true).then(res => {
					if (res.code == 1) {
						this.personInfo = res.data
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			// 跳转提现
			tztxclick() {
				uni.navigateTo({
					url: '/pages/mypage/tixian?type=3&styc_account_id='+this.styc_account_id
				})
			},
			// 跳转返还明细
			tzfhmx(){
				uni.navigateTo({
					url:'/pages/mypage/fanhuanmx'
				})
			},
			// 跳转转增页面
			tzzz() {
				uni.navigateTo({
					url: '/pages/mypage/zhuanzeng'
				})
			},
			// 类型切换
			changelx(id){
				this.selecttime = id
			},
			// 选择时间段
			selecTimeBtn(id) {
				this.mindate = ""
				this.selecttime = id
				this.startime = "开始时间"
				this.endtime = "结束时间"
			},
			date(timer) {
				var date = new Date(timer); //当前时间
				var year = date.getFullYear() //返回指定日期的年份
				var month = repair(date.getMonth() + 1); //月
				var day = repair(date.getDate()); //日
				var curTime = year + "-" + month + "-" + day

				function repair(i) {
					if (i >= 0 && i <= 9) {
						return "0" + i;
					} else {
						return i;
					}
				}
				return curTime
			},
			zdysj() {
				this.selecttime = 0
				console.log("111111111111")
			},
			// 开始时间
			zconfirm(e) {
				console.log(e)
				this.mindate = e.value
				this.startime = this.date(e.value)
				this.zshow = false
			},
			zshijian() {
				this.zshow = true
			},
			//结束时间
			yconfirm(e) {
				console.log(e)
				this.endtime = this.date(e.value)
				this.yshow = false
			},
			yshijian() {
				if (this.mindate == "") {
					return
				}
				this.yshow = true
			},
			close(value) {
				this.show = false
				if(value==2){
					this.init()
				}
				// console.log('close');
			}
		}
	}
</script>

<style lang="scss" scoped>
	.xian {
		width: 22rpx;
		height: 0rpx;
		background-color: #999999;
		border: 1rpx solid #999999;
	}

	.shijianbtn {
		padding: 20rpx 65rpx;
		background: #F7F9FA;
		border-radius: 41rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.huisebtn {
		width: 198rpx;
		height: 80rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
		background: #F7F9FA;
		border-radius: 41rpx;
	}

	.haungsebtn {
		width: 198rpx;
		height: 80rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FAB536;
		background: rgba(250, 181, 54, .1);
		border-radius: 41rpx;
	}

	.sanshi {
		width: 33.33%;
	}

	.xiahuax {
		margin-top: 30rpx;
		padding-bottom: 30rpx;
		border-bottom: 2rpx solid rgba(0, 0, 0, 0.03);
	}

	.xiahuax:first-child {
		margin-top: 0rpx;
	}

	.xiahuax:last-child {
		padding-bottom: 0rpx;
		border-bottom: none;
	}

	.qhtext {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.qianshu {
		font-size: 32rpx;
		font-family: DIN Next LT Pro-Bold, DIN Next LT Pro;
		font-weight: bold;
		color: #FAB536;
	}

	.ershib1 {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #333333;
	}

	.shaxicon {
		width: 12rpx;
		height: 10rpx;
		background-size: 100% 100%;
		background-image: url('../../static/image/system/shaixuan.png');
	}

	.zhtext {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.banju {
		padding: 30rpx 30rpx 20rpx;
	}

	.line {
		width: 100%;
		border: 1rpx solid rgba(255, 255, 255, .1);
	}

	.baibtn {
		width: 194rpx;
		height: 65rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 10rpx;
		border: 2rpx solid #FFFFFF;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
	}

	.xbtext {
		font-size: 36rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
	}

	.bigbtext {
		font-size: 80rpx;
		font-family: DIN Next LT Pro-Bold, DIN Next LT Pro;
		font-weight: bold;
		color: #FFFFFF;
	}

	.toububjt {
		background-size: 100% 100%;
		width: 100%;
		box-sizing: border-box;
		padding: 76rpx 0 20rpx;
		background-image: url('../../static/image/system/jjtb.png');
	}
</style>
